package com.kuailework.module.${module}.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;
import com.kuailework.core.exception.GlobalException;
import com.kuailework.module.${module}.bean.${Entity};
import com.kuailework.module.${module}.mapper.${Entity}Mapper;
import com.kuailework.module.${module}.service.${Entity}Service;

@Service
public class ${Entity}ServiceImpl implements ${Entity}Service{

	@Autowired
    private ${Entity}Mapper ${entity}Mapper;
	

	@Override
	public PageInfo<${Entity}> page(int pageNum, int pageSize) {
		
		List<${Entity}> list = ${entity}Mapper.selectList(pageNum, pageSize);
		
		return new PageInfo<>(list);
	}


	@Override
	public ${Entity} edit(${Entity} record) {
		if (record.getId() == null) {
			${entity}Mapper.insertUseGeneratedKeys(record);
		} else {
			int i = ${entity}Mapper.updateByPrimaryKeySelective(record);
			if (i == 0) throw new GlobalException("更新失败, 更新的信息已被删除");
		}
		return record;
	}


	@Override
	public ${Entity} get(Long id) {
		return ${entity}Mapper.selectByPrimaryKey(id);
	}


	@Override
	public void remove(Long id) {
		${entity}Mapper.deleteByPrimaryKey(id);
	}

}
